#include <stdio.h>
#include <stdlib.h>
struct Student
    {
        int num;
        char egname[32];
        float grade;
    };
int main()
{ 

    int num,x; char egname[32]; float grade; struct Student stu; FILE *infile;
    
    if((infile=fopen("student.txt","r"))==NULL)
    {printf("A new file is being creating.\n");infile=fopen("Student.txt","a+b");}
    else
    {
        infile=fopen(" Student.txt","a+b");
        printf("This is the existing data:\n");
        while(fscanf(infile,"%d%s%f",&num,egname,&grade)!=EOF)

        printf("%-3d %-8s %5.2f\n",num,egname,grade);
    }
    while(1)
    {
        printf("Enter new data? Type '1' for yes, '0' for no.");
        scanf("%d",&x);
        if(x==0)
        break;
        else
        printf("Please enter the student number.\n");
        scanf("%d",&stu.num);
        printf("Please enter the English name.\n");
        scanf("%s",stu.egname);
        printf("Please enter the grade.\n");
        scanf("%f",&stu.grade);
        printf("please check the input.\n");
        printf("%d %s %.2f\n",stu.num,stu.egname,stu.grade);
        fprintf(infile,"%d %s %.2f\n",stu.num,stu.egname,stu.grade);
    }    
    return 0;
 }